import 'package:demo_flutter/common/vo/items.dart';
import 'package:dio/dio.dart';

class ItemApi {
  Future<List<Item>> getItems() async {
    String url = "http://101.34.9.40:8080/item/query";
    Dio dio = Dio();
    Response response = await dio.post(url, data: {});
    var responseMap = response.data;
    List mapList = responseMap['data'];
    List<Item> itemList = mapList.map((e) => Item.fromJson(e)).toList();
    return itemList;
  }

  Future<Item> getItemById(int? id) async {
    if (id == null) {
      throw "id不能为空";
    }
    String url = "http://101.34.9.40:8080/item/query";
    Dio dio = Dio();
    Response response = await dio.post(url, data: {"id": id});
    var responseMap = response.data;
    List mapList = responseMap['data'];
    List<Item> itemList = mapList.map((e) => Item.fromJson(e)).toList();
    return itemList[0];
  }
}
